﻿using System;
using UnityEngine;

namespace Core
{
    public abstract class AbstractSettingItem : Component, IAwake
    {
        public event Action<int> OnValueChanged;

        public int MaxValue { get; set; }

        public virtual void Awake()
        {
        }

        private int mValue;
        public int Value
        {
            get => mValue;
            set
            {
                mValue = Mathf.Clamp(value, 0, MaxValue);
                Refresh();
                OnValueChanged?.Invoke(value);
            }
        }

        public abstract void Refresh();

        public override string ToString()
        {
            return mValue.ToString();
        }

    }
}
